package Sport;


import java.sql.SQLException;
import java.util.List;
import players.Player;
import teams.Reflectable;
import teams.Sport;
import teams.Team;

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 *
 * @author denaas
 */
public class SportManager {
    static private DBManager dbManager = null;
    
    public SportManager() throws Exception {
        if (dbManager == null) {
            dbManager = new DBManager();
        }
    }
            
    
    public void addPlayer(Player player) throws SQLException {
        dbManager.addPlayer(player);
    }
    
    public void editPlayer(Player player) throws SQLException {
        dbManager.editPlayer(player);
    }
    
    public void removePlayer(Integer playerId) throws SQLException {
        dbManager.removePlayer(playerId.intValue());
    }
    
    public void addTeam(Team team) throws SQLException {
        dbManager.addTeam(team);
    }
    
    public void editTeam(Team team) throws SQLException {
        dbManager.editTeam(team);
    }
    
    public void removeTeam(Integer teamId, Integer sportId) throws SQLException {
        List players  = selectPlayers(null, teamId, sportId);
        for (int i=0; i < players.size(); ++i) {
            Player pl = (Player)players.get(i);
            removePlayer(pl.getId());
        }
        dbManager.removeTeam(teamId.intValue());
    }
    
    public List selectTeams(Integer teamId, Integer sportId) throws SQLNotFoundException, SQLException {
        return dbManager.selectTeams(teamId, sportId);
    }
    
    public List selectPlayers(Integer playerId, Integer teamId, Integer sportId) throws SQLException, SQLNotFoundException {
        return dbManager.selectPlayers(playerId, teamId, sportId);
    }
    
    public List selectPlayersQuery(Player plfrom, Player plto, Integer sportId) throws SQLException, SQLNotFoundException {
        return dbManager.selectPlayersQuery(plfrom, plto, sportId);
    }
}
